package org.vincen.filter;

import java.io.IOException;
import java.util.Date;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

public class MyFilter implements Filter {
	
	@SuppressWarnings("unused")
	private FilterConfig filterConfig = null;

	@Override
	public void destroy() {
		this.filterConfig = null;
	}

	@Override
	public void doFilter(ServletRequest arg0, ServletResponse arg1,
			FilterChain arg2) throws IOException, ServletException {
		System.out.println("-----记录访问时间：" + new Date());
		HttpServletRequest request = (HttpServletRequest)arg0;
		System.out.println("-----getRemoteAddr():" + request.getRemoteAddr());
		System.out.println("-----getRemoteHost():" + request.getRemoteHost());
		System.out.println("-----getRemotePort():" + request.getRemotePort());
		System.out.println("-----getRequestURL():" + request.getRequestURL().toString());
		System.out.println("-----getRequestURI():" + request.getRequestURI());
		System.out.println("-----getLocalAddr():" + request.getLocalAddr());
		System.out.println("-----getLocalName():" + request.getLocalName());
		System.out.println("-----getLocalPort():" + request.getLocalPort());
		arg2.doFilter(arg0, arg1);
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		this.filterConfig = arg0;
	}
}
